/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.dao.impl;

import com.ivanbiz.dao.KosDAO;
import com.ivanbiz.model.Kos;
import com.ivanbiz.service.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author City_Z
 */
public class KosDAOImpl extends GenericDAOImpl implements KosDAO {

    @Override
    public String getLastKode() throws Exception {
        Kos kos = null;
        String kode = "";
        try {
            HibernateUtil.beginTransaction();
            Session session = HibernateUtil.getSession();
            Query query = (Query) session.createQuery("from Kos k order by k.id desc");
            query.setFirstResult(0);
            query.setMaxResults(1);
            kos = (Kos) query.uniqueResult();
            if (kos != null) {
                kode = kos.getKodeKos();
            }
            HibernateUtil.commitTransaction();
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
            throw e;
        } finally {
            HibernateUtil.closeSession();
        }
        return kode;
    }
}
